package com.zygh.interactiveplatform.module.controller;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zygh.interactiveplatform.common.anno.PcLog;
import com.zygh.interactiveplatform.common.constant.SwaggerTagConst;
import com.zygh.interactiveplatform.common.domain.ResponseDTO;
import com.zygh.interactiveplatform.module.entity.vo.FirstFilterDto;
import com.zygh.interactiveplatform.module.entity.vo.WfdmVO;
import com.zygh.interactiveplatform.module.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;


@RestController
@RequestMapping("/invalid")
@Api(tags = {SwaggerTagConst.Admin.MANAGER_INVALID})
public class InvalidControoler {
    @Resource
    private CarstatisticsService carstatisticsService;
    @Resource
    private DataAccessService dataAccessService;
    @Resource
    private DataAccessTopsService dataAccessTopsService;
    @Resource
    private DataStructureService dataStructureService;
    @Resource
    private StorageTrendsService storageTrendsService;
    @Resource
    private IllegalVehicleServiceImpl illegalVehicleService;

    @ApiOperation(value = "车辆实时统计数据", notes = "车辆实时统计数据")
    @GetMapping("InvalidData")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_INVALID, content = "车辆实时统计数据")
    public ResponseDTO InvalidData() {
        return carstatisticsService.findCarstatisticsLast();
    }


    @ApiOperation(value = "数据接入情况", notes = "数据接入情况")
    @GetMapping("epolice6011")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_INVALID, content = "数据接入情况")
    public ResponseDTO epolice6011() {
        return dataAccessService.findDataAccessLast();
    }

    @ApiOperation(value = "数据接入tops", notes = "数据接入tops")
    @GetMapping("epoliceOne")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_INVALID, content = "数据接入tops")
    public ResponseDTO epoliceOne() {
        return dataAccessTopsService.findDataAccessTopsLast();
    }

    @ApiOperation(value = "数据结构分类", notes = "数据结构分类")
    @GetMapping("epoliceTwo")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_INVALID, content = "数据结构分类")
    public ResponseDTO epoliceTwo() {
        return dataStructureService.findDataStructureLast();
    }

    @ApiOperation(value = "统计每小时数据", notes = "统计每小时数据")
    @GetMapping("hour")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_INVALID, content = "统计每小时数据")
    public Object hour() {
        return storageTrendsService.findStorageTrendsAllDay();
    }



    @ApiOperation(value = "原始数据查询", notes = "原始数据查询")
    @PostMapping("originaldata")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_INVALID, content = "原始数据查询")
    public Object originaldata(@RequestBody FirstFilterDto firstFilterDto) {
        String URL = "http://192.168.10.130:8888/first-filter/query-filter";
        Map<String, Object> map = new HashMap<>(9);
        map.put("startDate", firstFilterDto.getStartDate());
        map.put("endDate", firstFilterDto.getEndDate());
        map.put("illegalCode", firstFilterDto.getIllegalCode());
        map.put("pageNum", firstFilterDto.getPageNum());
        map.put("pageSize", firstFilterDto.getPageSize());
        map.put("status", firstFilterDto.getStatus());
        map.put("hpzl", firstFilterDto.getHpzl());
        map.put("licenseNumber", firstFilterDto.getLicenseNumber());
        String paramString = JSON.toJSONString(map);
        String s = HttpUtil.post(URL, paramString);
        JSONObject result = JSONObject.parseObject(new String(s));
        return result;
    }

    @ApiOperation(value = "原始数据查询本地", notes = "原始数据查询本地")
    @PostMapping("findOriginalData")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_INVALID, content = "原始数据查询本地")
    public Object findOriginalData(@RequestBody WfdmVO wfdmVO){
        return illegalVehicleService.findOriginalData(wfdmVO);

    }
    @ApiOperation(value = "查询所有违法代码", notes = "查询所有违法代码")
    @GetMapping("findWfdm")
    @PcLog(logType = "1", module = SwaggerTagConst.Admin.MANAGER_INVALID, content = "查询所有违法代码")
    public Object findWfdm(){
        return illegalVehicleService.findWfdm();

    }



}
